/**
 * Created by denh on 16/12/14.
 */

var app = new Vue({
    el: '#content',
    data: {
        lists : []
    }
});

var appTitle = new Vue({
    el: '#title',
    data: {
        title: ""
    }
});

var token = '<?=$this->token?>';

result = common.getSession('meeting');
if (result) {
    apply(result);
} else {
    getData();
}

function getData() {
    id = common.getParam('id');
    common.serverUrl = '<?=BACK_INTERFACE_BASE_URL?>';
    common.net('CardController_cardDetail', token, id, function(result){
        if(result.code != 0) {
            common.showMsgBox(result.msg);
        } else {
            console.log(result.result);
            apply(result);
        }
    });
}

/**
 * 数据渲染
 * @param result
 */
function apply(result) {
    pic = eval('(' + result.result.pic[0] + ')');

    share_title = result.result.title;
    share_desc = result.result.title;
    share_imgUrl = pic.url;

    share(share_title, share_desc, share_imgUrl);

    lists = result.result.meetingExt.video;
    for(i=0; i<lists.length; i++) {
        lists[i]['videoDetailUrl'] = common.url('meeting', 'videoDetail', 'id='+lists[i].id);
        lists[i]['createTime'] = common.getDate(lists[i]['createTime']);
    }
    app.lists = lists;
    appTitle.title = result.result.title;
}

/**
 * 微信分享
 * @param share_title
 * @param share_desc
 * @param share_imgUrl
 */
function share(share_title, share_desc, share_imgUrl) {
    wx.config({
        debug: false,
        appId: '<?php echo $this->signPackage["appId"];?>',
        timestamp: '<?php echo $this->signPackage["timestamp"];?>',
        nonceStr: '<?php echo $this->signPackage["nonceStr"];?>',
        signature: '<?php echo $this->signPackage["signature"];?>',
        jsApiList: [
            'onMenuShareAppMessage',
            'onMenuShareTimeline',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'onMenuShareQZone'
        ]
    });
    links = '';
    weixinShare(share_title, share_desc, links, share_imgUrl);
}
